package com.hzbank.juc.pattern;

/**
 * @description:
 * @author: libugu@cskaoyan.com
 * @date 2023/12/22 - 14:45
 */
public class GuardedObject {

    private Object resposne;
    private final Object lock = new Object();

    // 获取结果
    public Object get(){
        synchronized (lock){

            while (resposne == null){
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            return resposne;
        }
    }


    // 产生结果
    public void complete(Object resposne){
        synchronized (lock){
            this.resposne = resposne;
            lock.notifyAll();
        }
    }

}
